package com.cy.pj.module.controller;

import com.cy.pj.module.pojo.ResponseResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class JsonObjectController {

    @RequestMapping("/doConvertResponseToJson")
    @ResponseBody
    public ResponseResult doConvertResponseToJson(){
        ResponseResult result = new ResponseResult();
        result.setCode(200);
        result.setMessage("ok");
        return result;
    }

    @RequestMapping("/doConvertResponseToJson02")
    @ResponseBody
    public Map<String,Object> doConvertResponseToJson02(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("aaa", "b");
        map.put("sss", true);
        return map;
    }

    @RequestMapping("/doConvertResponseToJson03")
    @ResponseBody
    public List<Map<String,Object>> doConvertResponseToJson0203(){
        ArrayList<Map<String,Object>> list = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        map.put("aaa", "b");
        map.put("sss", true);
        list.add(map);

        map = new HashMap<>();
        map.put("bbb", "c");
        map.put("sss", true);
        list.add(map);
        return list;

    }
}
